//
//  SYYBaseVC.m
//  NineteenBook
//
//  Created by xhkj on 2021/8/4.
//  Copyright © 2021 UP. All rights reserved.
//

#import "SYYBaseVC.h"

@interface SYYBaseVC ()

@property (nonatomic, assign)BOOL showNavBar;

@end

@implementation SYYBaseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)setStatusType:(UIStatusBarStyle)statusType{
    _statusType = statusType;
    [self setNeedsStatusBarAppearanceUpdate];
}

-(void)setStatusHidden:(BOOL)statusHidden{
    _statusHidden = statusHidden;
    [self setNeedsStatusBarAppearanceUpdate];
}

-(UIStatusBarStyle)preferredStatusBarStyle {
    return self.statusType;
}

- (BOOL)prefersStatusBarHidden{
    return self.statusHidden;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if (self.showNavBar) {
        [self.view bringSubviewToFront:self.navView];
        if (self.navigationController.childViewControllers.count>1) {
            [self.navLeftBtn setImage:HHLIBIMAGE(@"ic_back_black") forState:UIControlStateNormal];
        }
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
}




//navView
- (UIImageView *)navView{
    if (!_navView) {
        _navView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,ScreenWidth, NavBarHeight)];
        _navView.backgroundColor = HHColorHex(0xFFFFFF);
        _navView.userInteractionEnabled = YES;
        [self.view addSubview:_navView];
        self.showNavBar = YES;
    }
    return _navView;
}
- (void)setNavBarColor:(UIColor *)navBarColor{
    _navBarColor = navBarColor;
    self.navView.backgroundColor = navBarColor;
}

// 创建导航栏的titleLabel
- (UILabel *)navTitleLabel{
    if (!_navTitleLabel) {
        _navTitleLabel = [UILabel new];
        _navTitleLabel.textColor =  HHColorHex343434;
        _navTitleLabel.font = HHBoldFont(18);
        _navTitleLabel.textAlignment = NSTextAlignmentCenter;
        _navTitleLabel.text = self.navTitle;
        [self.navView addSubview:_navTitleLabel];
        _navTitleLabel.sd_layout.topEqualToView(self.navView).offset(StatusBarHeight)
        .centerXEqualToView(self.navView)
        .widthIs(ScreenWidth*0.55)
        .heightIs(ItemBtnHeight);
    }
    return _navTitleLabel;
}
- (void)setNavTitle:(NSString *)navTitle{
    _navTitle = navTitle;
    self.navTitleLabel.text = navTitle;
}

// 创建导航栏左边按钮
- (UIButton *)navLeftBtn{
    if (!_navLeftBtn) {
        _navLeftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _navLeftBtn.tintColor = [UIColor clearColor];
        [_navLeftBtn setTitleColor: HHColorHex343434 forState:UIControlStateNormal];
        [_navLeftBtn.titleLabel setFont: HHFont14];
        [_navLeftBtn setTitle:@"" forState:UIControlStateNormal];
        [_navLeftBtn addTarget:self action:@selector(leftBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.navView addSubview:_navLeftBtn];
        _navLeftBtn.sd_layout.topEqualToView(self.navView).offset(StatusBarHeight)
        .leftEqualToView(self.navView).offset(ItemBtnSpace)
        .widthIs(ItemBtnWidth)
        .heightIs(ItemBtnHeight);
    }
    return _navLeftBtn;
}
- (void)setNavLeftBtnTitle:(NSString *)navLeftBtnTitle{
    _navLeftBtnTitle = navLeftBtnTitle;
    [self.navLeftBtn setTitle:navLeftBtnTitle forState:UIControlStateNormal];
}
- (void)setNavLeftBtnImage:(NSString *)navLeftBtnImage{
    _navLeftBtnImage = navLeftBtnImage;
    if (navLeftBtnImage) {
        [self.navLeftBtn setImage:[HHIMAGE(navLeftBtnImage) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    }
}

// 创建导航栏右边按钮
- (UIButton *)navRightBtn{
    if (!_navRightBtn) {
        _navRightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _navRightBtn.tintColor = [UIColor clearColor];
        [_navRightBtn setTitleColor: HHColorHex343434 forState:UIControlStateNormal];
        [_navRightBtn.titleLabel setFont: HHFont14];
        [_navRightBtn setTitle:@"" forState:UIControlStateNormal];
        [_navRightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.navView addSubview:_navRightBtn];
        _navRightBtn.sd_layout.topEqualToView(self.navView).offset(StatusBarHeight)
        .rightEqualToView(self.navView).offset(-ItemBtnSpace)
        .widthIs(ItemBtnWidth)
        .heightIs(ItemBtnHeight);
    }
    return _navRightBtn;
}
- (void)setNavRightBtnTitle:(NSString *)navRightBtnTitle{
    _navRightBtnTitle = navRightBtnTitle;
    [self.navRightBtn setTitle:navRightBtnTitle forState:UIControlStateNormal];
}
- (void)setNavRightBtnImage:(NSString *)navRightBtnImage{
    _navRightBtnImage = navRightBtnImage;
    if (self.navRightBtnImage) {
         [self.navRightBtn setImage:[HHIMAGE(navRightBtnImage) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    }
}

- (void)leftBtnAction:(UIButton *)leftBtn{
    if (self.navigationController.childViewControllers.count > 1) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)rightBtnAction:(UIButton *)rightBtn{
}



@end
